package lx.exalarm.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import static lx.exalarm.database.DBConstants.*;

/**
 * Created by liuxu on 15-2-28.
 */
class DBHelper extends SQLiteOpenHelper {

    DBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_ACTION + " (" +
                ACTION_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                ACTION_TYPE + " INTEGER," +
                ACTION_INTERVAL + " INTEGER," +
                ACTION_DURANCE + " INTEGER," +
                ACTION_DATA + " VARCHAR," +
                ACTION_ENABLED + " INTEGER," +
                ACTION_NEXT + " INTEGER" +
                ")");

        db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_ALARM + " (" +
                ALARM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                ALARM_HOUR + " INTEGER," +
                ALARM_MINUTE + " INTEGER," +
                ALARM_REPEAT + " INTEGER," +
                ALARM_ENABLED + " INTEGER," +
                ALARM_ACTION + " INTEGER" +
                ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ACTION);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALARM);
        onCreate(db);
    }
}